<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Autumn Framework</title>
    <link rel="shortcut icon" href="https://github.com/shuaijunlan/Autumn-Framework/raw/master/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="Lib/layui_v2.2.3/css/layui.css">
    <link rel="stylesheet" href="static/css/login.css">
</head>
<body>
<div class="layui-carousel video_mask" id="login_carousel" >
    <div carousel-item>
        <div class="carousel_div5"></div>
    </div>
    <div class="login layui-anim layui-anim-up">
        <h1>Autumn Blog</h1></p>
        <form class="layui-form">
            <div class="layui-form-item">
                <input type="text" name="username" lay-verify="required" placeholder="请输入账号" autocomplete="off"  value="" class="layui-input">
            </div>
            <div class="layui-form-item">
                <input type="password" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off" value="" class="layui-input">
            </div>
            <div class="layui-form-item form_code">
                <input class="layui-input" name="code" placeholder="验证码" lay-verify="required" type="text" autocomplete="off">
                <div class="code"><img src="captcha.do" width="116" height="36"></div>
            </div>
            <button class="layui-btn login_btn" lay-submit="" lay-filter="login">登陆系统</button>
        </form>
        <a style="padding-left: 70%; color: white; line-height: 35px; cursor: help;" id="register">没有账号？</a>
        <a style="padding-left: 20%; color: white; line-height: 50px; cursor: help;" href="https://shuaijunlan.cn/autumn-cms/" target="_blank">体验一下Autumn-cms？</a>

    </div>

</div>

</body>

</html>
<script src="Lib/jquery/jquery-3.2.1.min.js"></script>
<script src="Lib/layui_v2.2.3/layui.js"></script>
<script src="BasePlu/Base.js"></script>
<script>
    layui.config({
        base : "static/js/"
    }).use(['form','layer','jquery','common','carousel', 'element'], function () {
        var $ = layui.jquery,
            form = layui.form,
            common = layui.common,
            carousel = layui.carousel;

        /**背景图片轮播*/
        carousel.render({
            elem: '#login_carousel',
            width: '100%',
            height: '100%',
            interval:3000,
            arrow: 'none',
            anim: 'fade',
            indicator:'none'
        });
        /**重新生成验证码*/
        function reqCaptcha() {
            var url = "captcha.do?nocache=" + new Date().getTime()
            $('.code img').attr("src",url)
        }
        /**点击验证码重新生成*/
        $('.code img').on('click', function () {
            reqCaptcha();
        });
        /**监听登陆提交*/
        form.on('submit(login)', function (data) {
            //弹出loading
            var loginLoading = top.layer.msg('登陆中，请稍候', {icon: 16, time: false, shade: 0.8});
            //记录ajax请求返回值
            var ajaxReturnData;

            //登陆验证
            $.ajax({
                url: 'loginCheck.do',
                type: 'post',
                async: false,
                data: data.field,
                success: function (data) {
                    ajaxReturnData = data;
                }
            });
            //登陆成功
            if (ajaxReturnData.code == 0000) {
                window.location.href="editor";
                top.layer.close(loginLoading);
                return false;
            } else if (ajaxReturnData.code == 4005){
                layer.confirm('此账号没有进行验证，为保证您的数据安全，请您注册新的账号。', {icon: 3, title:'提示'});
                return false;
            } else {
                top.layer.close(loginLoading);
                common.cmsLayErrorMsg(ajaxReturnData.msg);
                reqCaptcha();
                return false;
            }
        });

        $("#register").click(function () {

            layui.$.post('Sys/plugin/SysConfig/RegisterPage/RegisterPage.html', {}, function (str) {
                var init = {
                    username : 'admin'
                    ,id : -1
                };
                layer.open({
                    type: 1
                    ,title: "新用户注册"
                    ,shade: 0.8
                    ,id: 'registerPage  ' //设定一个id，防止重复弹出
                    ,btnAlign: 'c'
                    ,moveType: 1 //拖拽模式，0或者1
                    ,content: str
                    , skin: 'layui-layer-molv'
                    ,success: function(layero){
                    }
                });
                form.render();
                form.on('submit(RegisterPage)', function(data){
                    var loginLoading = layer.msg('注册中，请稍候...', {icon: 16, time: false, shade: 0.8});
                    if (data.field.password != data.field.repassword){
                        layer.msg("两次密码不一致");
                        layer.close(loginLoading);
                    }else {
                        var user = {
                            user_login_name : data.field.user_login_name
                            ,email : data.field.email
                            ,password : data.field.password
                            ,creator : init.username
                            ,creator_id : init.id
                            ,modifier : init.username
                            ,modifier_id : init.id
                            ,status : 2
                        };
                        Fv.ajax.post("register/userRegister/", user, function (data) {
                                if (data.code == '1111'){
                                    layer.closeAll("page");
                                    layer.confirm('请查收您的激活邮件(可能在垃圾箱中)，点击链接激活，否则无法使用此账号登录?', {icon: 3, title:'提示'});
                                }else if (data.code == '4001'){
                                    layer.msg("邮件发送失败");
                                }else if (data.code == '5000'){
                                    layer.msg("登录名已存在");
                                }else {
                                    layer.msg("注册失败，请稍后再试");
                                }
                                layer.close(loginLoading);
                            }
                            ,function () {
                                layer.close(loginLoading);
                                layer.msg("系统异常");
                            });
                    }
                    return false;
                });
            })
        })
    });
</script>